﻿namespace PropOnline.Stores.Data
{
    using System;

    public static class NullableTypesExtensions
    {
        public static T ValueOrDefault<T>(this Nullable<T> nullable, T defaultValue) where T : struct
        {
            return nullable.HasValue ? nullable.Value : defaultValue;
        }

        public static RT TransformValueOrDefault<T, RT>(this Nullable<T> nullable, Func<T, RT> transformation, RT defaultValue) where T : struct
        {
            return nullable.HasValue ? transformation(nullable.Value) : defaultValue;
        }
    }
}